<%-- 
    Document   : lista
    Created on : 08/08/2009, 19:44:28
    Author     : Flaviano
    Using AuthSub with the Google Data API Client Libraries - http://code.google.com/intl/pt-BR/apis/gdata/authsub.html
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import= "com.google.gdata.client.docs.*"%>
<%@ page import= "com.google.gdata.client.*"%>
<%@ page import= "com.google.gdata.data.docs.*"%>
<%@ page import= "com.google.gdata.data.acl.*"%>
<%@ page import= "com.google.gdata.util.*"%>
<%@ page import= "com.google.gdata.client.docs.DocsService" %>
<%@ page import= "com.google.gdata.data.BaseEntry"%>
<%@ page import= "com.google.gdata.util.AuthenticationException"%>
<%@ page import= "com.google.gdata.client.docs.DocsService"%>
<%@ page import= "com.google.gdata.util.ServiceException"%>
<%@ page import= "com.google.gdata.data.docs.DocumentListEntry"%>
<%@ page import= "com.google.gdata.data.docs.DocumentEntry"%>
<%@ page import= "com.google.gdata.data.docs.DocumentListFeed"%>
<%@ page import= "com.google.gdata.data.PlainTextConstruct"%>
<%@ page import= "com.google.gdata.client.DocumentQuery"%>
<%@ page import= "com.google.gdata.client.http.AuthSubUtil"%>
<%@ page import= "java.net.URL" %>
<%@ page import= "java.io.IOException"%>
<%@ page import= "java.net.MalformedURLException"%>
<%@ page import= "javax.servlet.http.*" %>
<%@ page import="javax.servlet.http.HttpSession" %>
<%@ page  import= "java.util.List" %>


<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Lista de Arquivos</title>
        <meta name="verify-v1" content="zfoUspYD1cvwwh+wysRH5nASscL4zSVtohs3yVbHaQg=" />
    </head>
    <body>        
        <h1>Lista de Arquivos</h1>
        
        <p>Ao clicar em abrir, uma janela será aberta com o documento dentro da interface do Google Docs.</p>
        <%        
            //Extract the single-use token
            String singleUseToken = AuthSubUtil.getTokenFromReply(request.getQueryString());
            String sessionToken = AuthSubUtil.exchangeForSessionToken(singleUseToken, null);//isso da erro com o GAE

            DocsService client = new DocsService("yourCo-yourAppName-v1");
            //usa o token da seção.
            //client.setAuthSubToken(sessionToken, null);
            client.setAuthSubToken(sessionToken);
            URL metafeedUrl = new URL("http://docs.google.com/feeds/documents/private/full");
            DocumentListFeed resultFeed = client.getFeed(metafeedUrl, DocumentListFeed.class);
            List<DocumentListEntry> entries = resultFeed.getEntries();
                   %>
          
          <p><%=singleUseToken %> </p>
          
        <table border="1">
            <thead>
                <tr>
                    <th>Nome do Arquivo</th> <th>Link para Abrir</th>
                </tr>
            </thead>
            <tbody>
                <%
                for (int i = 0; i < entries.size(); i++) {
                    DocumentListEntry entry = entries.get(i);
                    //System.out.println("\t" + entry.getTitle().getPlainText());
                %><tr><td> <%=entry.getTitle().getPlainText()%></td>
                    <td> <a href="<%=entry.getDocumentLink().getHref()%>" target="_blank"> Abrir </a></td><%

                               }
                    %>
                </tr>
            </tbody>
        </table>
                    <p>Total de Arquivos: <%=entries.size()%><br><a href="http://localhost:8080/">Voltar</a></p><%
                    AuthSubUtil.revokeToken(sessionToken, null);
        %>
    </body>
</html>




